package com.demo.controller;

import com.demo.common.R;
import com.demo.domain.User;
import com.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.swing.*;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags="用户详情")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 发送验证码
     * @param user
     * @param session
     * @return
     */
    @PostMapping("/sendMsg")
    @ApiOperation(value = "发送验证码")
    public R<String> sendMsg(@RequestBody User user, HttpSession session) {
        log.info("获取到的user为 {}", user.toString());
        return userService.sendMsg(user,session);
    }

    /**
     * 登录验证
     * @param map
     * @param session
     * @return
     */
    @PostMapping("/login")
    @ApiOperation(value = "登录验证")
    public R<User> login(@RequestBody Map map,HttpSession session) {
        log.info("获取到的map为 {} session为 {}", map.toString(), session);
        return userService.login(map,session);
    }

    /**
     * 退出登录
     * @param session
     * @return
     */
    @PostMapping("/loginout")
    @ApiOperation(value = "退出登录")
    public R<String> loginout(HttpSession session){
        return userService.loginout(session);
    }
}
